package com.develophelper.aliyun.rocketmq.annotation;

import com.aliyun.openservices.ons.api.ExpressionType;
import com.aliyun.openservices.shade.com.alibaba.rocketmq.common.protocol.heartbeat.MessageModel;
import org.springframework.stereotype.Component;

import java.lang.annotation.*;

/**
 * @author snaildev
 * @date 2021/05/12
 **/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Component
public @interface RocketMQMessageListener {
    String NAME_SERVER_PLACEHOLDER = "${aliyun.rocketmq.name-server:}";
    String CONSUMER_GROUP_ID = "${aliyun.rocketmq.group-id:}";
    String ACCESS_KEY_PLACEHOLDER = "${aliyun.rocketmq.access-key:}";
    String SECRET_KEY_PLACEHOLDER = "${aliyun.rocketmq.secret-key:}";

    /**
     * Consumers of the same role is required to have exactly same subscriptions and consumerGroup to correctly achieve
     * load balance. It's required and needs to be globally unique.
     * <p>
     * <p>
     * See <a href="http://rocketmq.apache.org/docs/core-concept/">here</a> for further discussion.
     */
    String consumerGroup() default CONSUMER_GROUP_ID;

    /**
     * Topic name.
     */
    String topic();

    /**
     * Control how to selector message.
     *
     * @see ExpressionType
     */
    ExpressionType selectorType() default ExpressionType.TAG;

    /**
     * Control which message can be select. Grammar please see {@link ExpressionType#TAG} and {@link ExpressionType#SQL92}
     */
    String selectorExpression() default "*";

    /**
     * Control consume mode, you can choice receive message concurrently or orderly.
     */
    ConsumeMode consumeMode() default ConsumeMode.CONCURRENTLY;

    /**
     * Control message mode, if you want all subscribers receive message all message, broadcasting is a good choice.
     */
    MessageModel messageModel() default MessageModel.CLUSTERING;

    /**
     * Max consumer thread number.
     */
    int consumeThreadMax() default 64;

    /**
     * Maximum amount of time in minutes a message may block the consuming thread.
     */
    long consumeTimeout() default 15L;

    /**
     * Maximum amount of times reconsume when failure.
     */
    int maxReconsumeTimes() default 16;

    /**
     * The property of "access-key".
     */
    String accessKey() default ACCESS_KEY_PLACEHOLDER;

    /**
     * The property of "secret-key".
     */
    String secretKey() default SECRET_KEY_PLACEHOLDER;

    /**
     * The property of "name-server".
     */
    String nameServer() default NAME_SERVER_PLACEHOLDER;

    /**
     * the trace id for logger
     */
    String traceId() default "X-Request-ID";
}
